<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a>支付渠道</a>
        <a><cite>编辑配置</cite></a>
    </span>
</div>
<style>
    .layui-form-label {
        width:15% !important;
        margin-left:1%;
    }

    .layui-input, .layui-textarea {
        width: 50%;
    }

    .saveBtn {
        margin-left: 60px;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">编辑配置</li>
            </ul>
            <div class="layui-tab-content">
                <form class="layui-form  layui-form-pane" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list">
                    <div class="layui-form-item">
                        <label class="layui-form-label">ID</label>
                        <div class="layui-input-block">
                            <input type="text" id="id" name="id"  readonly="readonly" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">渠道类型</label>
                        <div class="layui-input-block">
                            <!--<input type="radio" name="channelType" title="账户支付" value="accountpay" disabled />-->
                            <input type="radio" name="channelType" title="微信支付" value="wxpay" disabled />
                            <input type="radio" name="channelType" title="支付宝" value="alipay" disabled />
                            <!--<input type="radio" name="channelType" title="快钱支付" value="kqpay" disabled />
                            <input type="radio" name="channelType" title="威富通支付" value="swiftpay" disabled />
                            <input type="radio" name="channelType" title="银盈通支付" value="gomepay" disabled />-->
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">渠道ID</label>
                        <div class="layui-input-block">
                            <input type="text" id="channelId" name="channelId" placeholder="请输入渠道ID" lay-verify="required" readonly="readonly" autocomplete="off" disabled class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用场景</label>
                        <div class="layui-input-block" >
                            <input type="radio" name="scene" title="移动APP" value="1" disabled >
                            <input type="radio" name="scene" title="移动网页" value="2" disabled >
                            <input type="radio" name="scene" title="PC网页" value="3" disabled >
                            <input type="radio" name="scene" title="微信公众平台" value="4" disabled >
                            <!--<input type="radio" name="scene" title="手机扫码" value="5" disabled >-->
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block" >
                            <input type="radio" name="state" title="开启" value="1" />
                            <input type="radio" name="state" title="关闭" value="0" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注信息</label>
                        <div class="layui-input-block">
                            <input type="text" id="remark" name="remark" placeholder="请输入备注信息" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">渠道参数</label>
                        <div class="layui-input-block">
                            <textarea name="param" id="param" placeholder="请输入渠道支付参数" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn saveBtn" lay-submit="" lay-filter="channelUpdate">保存</button>
                            <a class="layui-btn backBtn" onclick="back()">返回</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['table','util','admin', 'form'], function() {
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,admin = layui.admin
            ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        var id = layui.router().search.id;
        admin.req({
            type: 'post',
            url: layui.setter.baseUrl + '/config/channel/get',
            data: {
                id : id
            },
            error: function(err) {
                layer.alert(JSON.stringify(err.field), {
                    title: '错误提示'
                })
            },
            success: function(res) {
                if (res.code == 0) {
                    // 2 赋值
                    data = res.data;

                    form.render(null, 'layuiadmin-app-form-list');
                    $("#id").val(data.id);
                    $("#channelId").val(data.channelId);
                    if (res.data.channelType == 'wxpay') {
                        $("input[name='channelType'][value='wxpay']").attr("checked", true);
                    } else if (res.data.channelType == 'alipay') {
                        $("input[name='channelType'][value='alipay']").attr("checked", true);
                    } else if (res.data.channelType == 'kqpay') {
                        $("input[name='channelType'][value='kqpay']").attr("checked", true);
                    } else if (res.data.channelType == 'swiftpay') {
                        $("input[name='channelType'][value='swiftpay']").attr("checked", true);
                    } else if (res.data.channelType == 'gomepay') {
                        $("input[name='channelType'][value='gomepay']").attr("checked", true);
                    } else if (res.data.channelType == 'accountpay') {
                        $("input[name='channelType'][value='accountpay']").attr("checked", true);
                    }
                    if (res.data.scene == '1') {
                        $("input[name='scene'][value='1']").attr("checked", true);
                    } else if(res.data.scene == '2') {
                        $("input[name='scene'][value='2']").attr("checked", true);
                    } else if(res.data.scene == '3') {
                        $("input[name='scene'][value='3']").attr("checked", true);
                    } else if(res.data.scene == '4') {
                        $("input[name='scene'][value='4']").attr("checked", true);
                    } else if(res.data.scene == '5') {
                        $("input[name='scene'][value='5']").attr("checked", true);
                    }
                    if (res.data.state == 1) {
                        $("input[name='state'][value='1']").attr("checked", true);
                    } else {
                        $("input[name='state'][value='0']").attr("checked", true);
                    }

                    $('#remark').val(data.remark);
                    $('#param').val(data.param);

                    form.render();
                } else{
                    layer.alert(res.msg,{
                        title:"请求失败"
                    })
                }
            }
        })

        form.on('submit(channelUpdate)', function(data) {
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/channel/update', // 模拟接口,
                data: data.field,
                error: function(err){
                    layer.alert(err.msg,{
                        title:"请求失败"
                    })
                },
                success: function(res) {
                    if (res.code == 0) {
                        /*layer.alert(res.msg,{
                            title: "保存成功"
                        }, function(index) {
                            table.reload('tableReload');
                            layer.closeAll();
                         })*/
                        layer.msg('保存成功', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        }, function(){
                            back();
                        });
                    }else {
                        /*layer.alert(res.msg,{title: '保存失败'})*/
                        layer.msg('保存失败', {
                            offset: '15px'
                            ,icon: 1
                            ,time: 1000
                        });
                    }
                }
            })

        });

    })

    function back(){
        location.href = layui.setter.baseLocal + "config/channel/index";
    }
</script>